<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>修改用户记录</title>
    <!-- 引入 Bootstrap 4 的 CSS 文件 -->
    <link rel="stylesheet" href="./css/bootstrap.min.css">
</head>
<body>
    <?php 
        // echo $_GET['id'];
        require_once "conn.php";
        $result = mysqli_query($link,"SELECT * FROM users WHERE id='".$_GET['id'] ."'");
        $row= mysqli_fetch_array($result);
        if(count($_POST)>0){
            mysqli_query($link,"UPDATE users set name='" . $_POST['name'] ."',mobile='" . $_POST['mobile'] . "',email='" . $_POST['email'] ."' WHERE id='" . $_POST['id'] . "'");
        header("location: index.php");
            exit();
        }
    ?>
    <div class="container py-5">
        <h1 class="display-4">修改一条用户记录</h1>
        <form method="post" action="./update.php">
            <div class="row">
                <div class="col-md-8">
                    <div class="form-group">
                        <label for="name">姓名</label>
                        <input type="text" class="form-control"name="name" value="<?php echo $row['name']; ?>">
                    </div>
                </div>
                <div class="col-md-8">
                    <div class="form-group">
                        <label for="email">邮箱</label>
                        <input type="text" class="form-control" name="email" value="<?php echo $row['email']; ?>">
                    </div>
                </div>
                <div class="col-md-8">
                    <div class="form-group">
                        <label for="mobile">手机号</label>
                        <input type="text" class="form-control" name="mobile" value="<?php echo $row['mobile']; ?>">
                    </div>
                </div>
            </div>
            <!-- 提交按钮放在最下面，以便所有输入字段都可见 -->
            <input type="hidden" name="id" value="<?php echo $row['id']; ?>">
            <button type="submit" class="btn btn-primary" name="update">修改</button>
            <button type="button" class="btn btn-success"><a href="index.php">返回首页</a></button>
        </form>
    </div>
</body>
</html>